#include "shimadzuprotocol.h"
#include "shimadzuparsepacket.h"
#include "shimadzusendpacket.h"
#include "shimadzufindpacket.h"

ShimadzuProtocol::ShimadzuProtocol(electronicscale::ElectronicScaleParam &param, QObject *parent)
    : ShimadzuProtocol(param, * new ShimadzuProtocolData(), parent)
{

}

ShimadzuProtocol::ShimadzuProtocol(electronicscale::ElectronicScaleParam &param, ShimadzuProtocolData &data, QObject *parent)
    : BaseProtocol (data, parent)
{
    m_param = &param;

    ShimadzuParsePacket *parser = new ShimadzuParsePacket(param, data, this);
    ShimadzuSendPacket *sender = new ShimadzuSendPacket(data, this);
    connect(sender, &BaseSendPacket::requestSend, this, &BaseProtocol::requestSend);

    connect(parser, &ShimadzuParsePacket::parseCompleted, this, &ShimadzuProtocol::parseCompleted);

    data.m_parser = parser;
    data.m_sender = sender;
}

ShimadzuProtocol::~ShimadzuProtocol()
{
    delete m_d->m_sender;
    delete m_d->m_parser;
}

ShimadzuSendPacket *ShimadzuProtocol::getSender()
{
    return static_cast<ShimadzuSendPacket*>(m_d->m_sender);
}
